package com.benbi.shequapi.controller;

import com.benbi.shequapi.service.PersonService;
import com.benbi.shequapi.utils.Result;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/person")
public class PersonController {
    @Resource
    PersonService personService;

    @RequestMapping("/login")
    public Result login(
            @RequestParam("account") String account,
            @RequestParam("password") String password,
            @RequestParam("type") int type) {
        return personService.personLogin(account, password, type);
    }

    @RequestMapping("/signup")
    public Result signup(
            @RequestParam("type") int type,
            @RequestParam("phone") String phone,
            @RequestParam("password") String password,
            @RequestParam("name") String name,
            @RequestParam("civilId") String civilId,
            @RequestParam("gender") int gender,
            @RequestParam("birthdate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date birthdate,
            @RequestParam(name="bno", required = false, defaultValue = "") String bno,
            @RequestParam(name="room", required = false, defaultValue = "") String room,
            @RequestParam(name="cid", required = false, defaultValue = "0") int cid){
        return personService.personSignup(type, phone, password, name, civilId, gender, birthdate, bno, room, cid);
    }

    @RequestMapping("/getPerson")
    public Result getPerson(@RequestParam("pid") int pid){
        return personService.getPersonById(pid);
    }

    @RequestMapping("/queryPerson")
    public Result queryPerson(
            @RequestParam("keyword") String keyword,
            @RequestParam("mode") int mode){
        return personService.queryPerson(keyword, mode);
    }

//    @RequestMapping("/test")
//    public Result test(@RequestParam("date") @DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss") Date date){
//        Person p = new Person();
//        p.setBirthdate(date);
//        System.out.println(date);
//        System.out.println(p.getBirthdate());
//        return new Result();
//    }

}
